//
//  oldServiceInfoView.m
//  laonianbang
//
//  Created by 勇拓 李 on 18/3/22.
//  Copyright © 2018年 zaiyou. All rights reserved.
//

#import "oldServiceInfoView.h"
#import "UIImageView+oldImageView.h"
#import "AppDelegate.h"

@interface oldServiceInfoView()
@property (weak, nonatomic) IBOutlet UIImageView *img;
@property (weak, nonatomic) IBOutlet UIButton *btn_choose;
@property (weak, nonatomic) IBOutlet UILabel *label_title;
@property (weak, nonatomic) IBOutlet UILabel *label_content;
@property (weak, nonatomic) IBOutlet UIButton *btn_cancel;

@end

@implementation oldServiceInfoView

- (void)awakeFromNib
{
    [super awakeFromNib];
    self.layer.cornerRadius = 6.f;
    self.layer.masksToBounds = YES;
    
    _btn_choose.layer.cornerRadius = 6.f;
    
    [_btn_choose addTarget:self action:@selector(btn_choose_tapped) forControlEvents:UIControlEventTouchDown];
    [_btn_cancel addTarget:self action:@selector(btn_cancel_tapped) forControlEvents:UIControlEventTouchDown];
    
    UIView *blackView = [UIView new];
    
    blackView.frame = [UIScreen mainScreen].bounds;
    
    [[AppDelegate getMainWindow] addSubview:blackView];
    
    blackView.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0  blue:0/255.0  alpha:.7];
    
    self.frame = CGRectMake(0, 0, 258, 398);
    
    [blackView addSubview:self];
    
    self.center = blackView.center;
    
    //加入点击手势remove分享界面
    UITapGestureRecognizer *tapView=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapChange:)];
    [blackView addGestureRecognizer:tapView];
    
    UITapGestureRecognizer *tapOtherView=[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapOther:)];
    [self addGestureRecognizer:tapOtherView];
    
    [self fadeIn];
}

- (void)setService:(oldService *)service
{
    _service = service;
    [_img showImage:service.pic];
    _label_title.text = service.cname;
    _label_content.text = service.content;
}

- (void)removeServiceView
{
    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:
     ^{
         CATransform3D transform = CATransform3DMakeScale(0.2, 0.2, 1.0);
         self.layer.transform = transform;
         self.alpha = 0.0;
     } completion:^(BOOL finished) {
         [self.superview removeFromSuperview];
         [self removeFromSuperview];
     }];
}

- (void)btn_choose_tapped
{
    [self.delegate chooseService:_service];
    [self removeServiceView];
}

- (void)btn_cancel_tapped
{
    [self removeServiceView];
}

#pragma mark - 动画
/**
 *  动画划出
 */
- (void)fadeIn
{
    self.alpha = 0.0;
    
    CGAffineTransform newTransform = CGAffineTransformMakeScale(0.2, 0.2);
    [self setTransform:newTransform];
    
    [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        CATransform3D transform = CATransform3DMakeScale(1, 1, 1.0);
        self.layer.transform = transform;
        self.alpha = 1.0;
    } completion:^(BOOL finished) {
        
    }];
}
/**
 *  动画关闭
 *
 */
-(void)tapChange:(UITapGestureRecognizer *)gureView
{
    [self removeServiceView];
}

- (void)tapOther:(UITapGestureRecognizer *)gureView
{
    
}

@end
